<?php
/**
 * @package		mod_qlform
 * @copyright	Copyright (C) 2012 ql.de All rights reserved.
 * @author 		Mareike Riegel mareike.riegel@ql.de
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

class modelQlMessager
{

	/**
	 * Method for raising error via JError
	 * @param   array  $arrErrors  errors to be raised 
	 */
	public function __construct($arrErrors,$type=1)
	{
		if (0==$type OR !is_array($arrErrors)) return false;
		if (1==$type) $this->getMessage($arrErrors);
		if (2==$type) $this->raiseErrors($arrErrors);
		if (3==$type) {$this->getMessage($arrErrors);$this->raiseErrors($arrErrors);}
		return true;
	}
	
	/**
	 * Method for raising error via JError
	 * @param   array  $arrErrors  errors to be raised 
	 */
	public function raiseErrors($arrErrors)
	{
		//print_r($arrErrors);die;
		if (is_array($arrErrors) AND 0<count($arrErrors))
		foreach ($arrErrors as $k=>$v) 
		{
			if (""!=trim(strip_tags($v['str'])))
			{
			if(isset($v['warning']) AND 1==$v['warning'])JError::raiseWarning(100,$v['str']);
			else JError::raiseNotice(100,$v['str']);
			}	
		}
	}
	/**
	 * Method for raising error via JError
	 * @param   array  $arrErrors  errors to be raised 
	 * @return   string errors to be shown 
	 */
	public function getMessage($arrErrors)
	{
		$message="";
		foreach ($arrErrors as $k=>$v) if (isset($v['str'])) $message.=$v['str']."<br />";
		return $this->message=$message;
	}
}